/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：绘制Resources资源管理器的窗体
* CreateTime：2020-07-07 17:51:55
* Version：1.0
* Modify Recorder：
*************************************************/

using System.Collections.Generic;
using TinyToolKit;
using UnityEditor;
using TinyToolKit.AssetLoad;
using UnityEngine;

namespace TinyToolKitEditor
{
    public class DrawWindowResLoad : DrawWindowBase
    {
        private TResourcesManager _resourcesManager;

        protected override void DrawInternalMainGUI()  
        {
            TinyToolWindowUtil.DrawDefaultEditorGUI(); 
            
            if (EditorApplication.isPlaying == false || TinyTool.Instance.HasManager<TResourcesManager>() == false) return;
            if (_resourcesManager == null) _resourcesManager = TinyTool.Instance.GetManager<TResourcesManager>();

            Dictionary<string, ResItem> allAssets = _resourcesManager.AllAssets;
            if (allAssets != null && allAssets.Count > 0)
            {
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                TinyToolWindowUtil.DrawTableHead("资源名", "路径");
                foreach (KeyValuePair<string, ResItem> item in allAssets) 
                {
                    string msg = string.Empty;
                    for (int i = 0; i < item.Value.objs.Length; i++)
                    {
                        if (i == item.Value.objs.Length - 1)
                            msg += item.Value.objs[i].name;
                        else
                            msg += item.Value.objs[i].name + ",";
                    }
                    EditorGUILayout.LabelField(msg, "Resources/" + item.Key);
                }
                TinyToolWindowUtil.DrawTableTail("总计：", allAssets.Count.ToString());
                EditorGUILayout.EndVertical();
            }
        }
    }
}
